<%@page contentType="text/html" pageEncoding="UTF-8"
        import="java.util.*,java.text.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Locale</title>
        <style type="text/css">
            td {white-space: nowrap;}
        </style>
    </head>
    <body>
        <table border="1">
            <caption>Locales</caption>
            <tr>
                <th>Locale</th>
                <th>Name</th>
                <th>Country</th>
                <th>Language</th>
                <th>Number</th>
                <th>Percent</th>
                <th>Currency Code</th>
                <th>Currency Symbol</th>
                <th>Currency</th>
                <th>Short Date</th>
                <th>Medium Date</th>
                <th>Long Date</th>
                <th>Full Date</th>
            </tr>
<%
String cc, cs;
DateFormat df1, df2, df3, df4; Date d=new Date();
NumberFormat nf1, nf2, nf3, nf4; double x=-(new Random()).nextDouble()*10000;
Map<String,Locale> tm=new TreeMap<String,Locale>(); // To sort by name
for(Locale l:Locale.getAvailableLocales())
    if(l.toString().startsWith("en")) tm.put("_"+l.toString(), l);
    else  tm.put(l.toString(), l); // To put English first
for(Locale l:tm.values()) {
    nf1=NumberFormat.getInstance(l);
    nf2=NumberFormat.getPercentInstance(l);
    nf2.setMinimumFractionDigits(2);
    nf3=NumberFormat.getCurrencyInstance(l);
    df1=DateFormat.getDateInstance(DateFormat.SHORT, l);
    df2=DateFormat.getDateInstance(DateFormat.MEDIUM, l);
    df3=DateFormat.getDateInstance(DateFormat.LONG, l);
    df4=DateFormat.getDateInstance(DateFormat.FULL, l);
    if(l.getCountry().isEmpty())
        cc=cs="";
    else {
        cc=Currency.getInstance(l).getCurrencyCode();
        cs=Currency.getInstance(l).getSymbol(l);
    }
%>
            <tr>
                <td><%= l %></td>
                <td><%= l.getDisplayName() %></td>
                <td><%= l.getDisplayCountry(l) %></td>
                <td><%= l.getDisplayLanguage(l) %></td>
                <td><%= nf1.format(x) %></td>
                <td><%= nf2.format(x/10000) %></td>
                <td><%= cc %></td>
                <td><%= cs %></td>
                <td><%= nf3.format(x) %></td>
                <td><%= df1.format(d) %></td>
                <td><%= df2.format(d) %></td>
                <td><%= df3.format(d) %></td>
                <td><%= df4.format(d) %></td>
            </tr>
<%
}
%>
        </table>
    </body>
</html>
